package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SecurityGiveWarnFlag;
import com.ruoyi.system.mapper.SecurityGiveWarnFlagMapper;
import com.ruoyi.system.service.SecurityGiveWarnFlagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 安全示警标识(SecurityGiveWarnFlag)表服务实现类
 *
 * @author makejava
 * @since 2022-11-15 15:36:22
 */
@Service
public class SecurityGiveWarnFlagServiceImpl implements SecurityGiveWarnFlagService {
    @Autowired
    private SecurityGiveWarnFlagMapper securityGiveWarnFlagDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SecurityGiveWarnFlag queryById(Integer id) {
        return this.securityGiveWarnFlagDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param securityGiveWarnFlag 筛选条件
     * @param pageRequest          分页对象
     * @return 查询结果
     */
    @Override
    public Page<SecurityGiveWarnFlag> queryByPage(SecurityGiveWarnFlag securityGiveWarnFlag, PageRequest pageRequest) {
        long total = this.securityGiveWarnFlagDao.count(securityGiveWarnFlag);
        return new PageImpl<>(this.securityGiveWarnFlagDao.queryAllByLimit(securityGiveWarnFlag, pageRequest), pageRequest, total);
    }

    @Override
    public List<SecurityGiveWarnFlag> selectList(SecurityGiveWarnFlag securityGiveWarnFlag) {
        return securityGiveWarnFlagDao.queryAll(securityGiveWarnFlag);
    }

    /**
     * 新增数据
     *
     * @param securityGiveWarnFlag 实例对象
     * @return 实例对象
     */
    @Override
    public SecurityGiveWarnFlag insert(SecurityGiveWarnFlag securityGiveWarnFlag) {
        this.securityGiveWarnFlagDao.insert(securityGiveWarnFlag);
        return securityGiveWarnFlag;
    }

    /**
     * 修改数据
     *
     * @param securityGiveWarnFlag 实例对象
     * @return 实例对象
     */
    @Override
    public SecurityGiveWarnFlag update(SecurityGiveWarnFlag securityGiveWarnFlag) {
        this.securityGiveWarnFlagDao.update(securityGiveWarnFlag);
        return this.queryById(securityGiveWarnFlag.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.securityGiveWarnFlagDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<SecurityGiveWarnFlag> securityGiveWarnFlags, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(securityGiveWarnFlags) || securityGiveWarnFlags.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        securityGiveWarnFlagDao.insertBatch(securityGiveWarnFlags);
        return "成功";
    }
}
